package com.hilaver.dzmis.main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import sun.security.smartcardio.SunPCSC.Factory;

import com.hilaver.dzmis.basicinfo.BiFactory;
import com.hilaver.dzmis.dao.BaseHibernateDAO;

public class AddSupplier {
	public static void main(String[] args) throws Exception{
		File cnFile = new File("D:/DZ_supplier_ch_zn.csv");
		File enFile = new File("D:/DZ_supplier_en.csv");
		FileReader cnReader = new FileReader(cnFile);
		FileReader enReader = new FileReader(enFile);
		BufferedReader cnBuffer = new BufferedReader(cnReader);
		BufferedReader enBuffer = new BufferedReader(enReader);
		String cnString = cnBuffer.readLine();
		String enString = enBuffer.readLine();
		BaseHibernateDAO dao = new BaseHibernateDAO();
		while((cnString = cnBuffer.readLine()) != null){
			enString = enBuffer.readLine();
			//System.out.println(cnString);
			//System.out.println(enString);
			String[] cnArray = cnString.split(",");
			String[] enArray = enString.split(",");
//			for (int i = 0; i < cnArray.length; i++) {
//				System.out.println(cnArray[i]);
//			}
//			
//			for (int i = 0; i < enArray.length; i++) {
//				System.out.println(enArray[i]);
//			}
			
			BiFactory factory = new BiFactory();
			factory.setNameCN(cnArray[1]);
			factory.setNameEN(enArray[1]);
			factory.setDepartmentCN(cnArray[2]);
			factory.setDepartmentEN(enArray[2]);
			factory.setAddressFactoryCN(cnArray[4]);
			factory.setAddressFactoryEN(enArray[4]);
			factory.setFactoryContactCN(cnArray[5]);
			factory.setFactoryContactEN(enArray[5]);
			factory.setFactoryPhone(cnArray[6]);
			factory.setFactoryEmail(cnArray[7]);
			factory.setFactoryFax(cnArray[8]);
			
			factory.setAddressCommercialCN(cnArray[9]);
			factory.setAddressCommercialEN(cnArray[9]);
			factory.setCommercialContactCN(cnArray[10]);
			factory.setCommercialContactEN(enArray[10]);
			factory.setCommercialPhone(cnArray[11]);
			factory.setCommercialEmail(cnArray[12]);
			factory.setCommercialFax(cnArray[13]);
			
			dao.saveOrUpdate(factory);
		}
	}
}
